#!/usr/bin/env node

const q = document.querySelector,
      $ = q.bind(document);

const $cmd = $('[name="cmd"]'),
      $exec = $('[type="button"]'),
      $res = $('pre');

const url = 'http://192.168.189.131:3000/';

$exec.onclick = () => {
    let cmd = $cmd.value;  
    cmd = new URLSearchParams({cmd}).toString();

    fetch(url, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        body: cmd
    })
    .then(res => res.json())
    .then(res => $res.textContent = res)
    .catch(error => {
        console.error('Error:', error);
    });
}



